﻿using System;
using MongoDB.Bson.Serialization.Attributes;

namespace Sustainalytics.Entities
{
    [BsonKnownTypes(typeof(Portfolio), typeof(AutomaticSystemPortfolio), typeof(ManualSystemPortfolio))]
    public class Portfolio : PortfolioBase
    {
        private int _companyCount;

        [BsonElement]
        public string NameLowercase
        {
            get
            {
                return string.IsNullOrEmpty(this.Name) ? string.Empty : this.Name.ToLowerInvariant();
            }
        }

        public DateTime DataCreated { get; set; }

        public DateTime? DateModified { get; set; }

        public string AddedByFullName { get; set; }

        public int CompanyCount { get { return _companyCount; } set { _companyCount = value; }  }

        public bool IsSystemPortfolio()
        {
            return this.IsAutomatic;
        }

        public bool IsCustomPortfolio()
        {
            return !this.IsAutomatic;
        }

        public bool IsMyCustomPortfolio(string userName)
        {
            return !(this.IsAutomatic && this.IsReadonly)
                   && (string.Compare(this.AddedByUserName, userName, StringComparison.InvariantCultureIgnoreCase) == 0);
        }
    }
}
